<template>
<Card  v-if="wordContent" :padding="0">
    <div class="word-template-title">
        <span>{{title}}</span>
        <!-- <a href="javascript:void(0)" title="编辑" v-if="isShow" v-on:click="editWord()">编辑</a>
        <a href="javascript:void(0)" title="保存" v-if="!isShow"v-on:click="addWord()">保存</a> -->
    </div>
    <div class="word-template-list">
        <p>{{ wordContent }}</p>
    </div>
    <!-- <div>
        <Input type="textarea"  v-if="!isShow" v-model="wordContent"  placeholder="请输入新的话术"></Input>
    </div> -->
</Card>
</template>
<style scoped>
    .word-template-title {
        display: flex;
        justify-content: space-between;
        align-items: center;
        background: #eaeaea;
        height: 25px;
        padding: 0 5px;
    }
    
    .word-template-list p {
        padding: 10px 5px;
    }
</style>
<script>
    import {
        mapGetters
    } from 'vuex'
    import wordService from 'service/wordoperation.js'
    export default {
        name: 'wordTemplate',
        data() {
            return {
                title: '',
                wordContent: '',
            }
        },
        props: {
            type: String
        },

        computed: {
            ...mapGetters({
                loginUserInfo: 'loginUserInfo'
            })
        },
        watch: {
            loginUserInfo(newVal, oldVal) {
                this.getMyWordTemplate(newVal.userId)
            },
            '$route' (to) {
                if (to.path.indexOf('/voicecall') > -1) {
                    this.getMyWordTemplate(this.loginUserInfo.userId)
                }

            }
        },

        mounted() {
            if (this.loginUserInfo.userId) {
                this.getMyWordTemplate(this.loginUserInfo.userId)
            }

        },
        methods: {
            async getMyWordTemplate(userId) {
                let jsondata = await wordService.myWord(userId)
                if (jsondata && this.type == 'start') {
                    this.title = "开始语"
                    this.wordContent = jsondata.startWord
                } else if (jsondata && this.type == 'end') {
                    this.title = "结束语"
                    this.wordContent = jsondata.endWord
                }

            }
        }
    };
</script>